package clamtitdictionary;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;



public class ITdictionary extends JFrame implements ActionListener{
    JTextField 	searchTextField;
    JTextArea  	tipOftheDayTextArea;
    JTextArea	outputDefTextArea;
    JButton    	searchBtn;
    JButton 	clearBtn;
    JButton 	addTermBtn;
    JButton 	myTermsBtn;
    JButton 	helpBtn;
    JButton		authorizeBtn;
    JButton		verifyBtn;
    JButton     approveBtn;
    JButton		allBtn;
    JButton 	aboutBtn;
    JButton 	homeBtn;
    JButton		logoBtn;
    JButton		a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
    JLabel 		tipOfTheDay;
    JPanel 		headerPanel;
    JPanel 		indexPanel;
    JPanel 		tipOftheDayPanel;
    JPanel 		outputPanel;
    JPanel 		mainPanel;
    JPanel 		menuPanel;
    JPanel 		buttonsPanel;
    JPanel		logoPanel;
    JPanel		footerPanel;
    JPanel mainHeaderPanel;
    JScrollPane scrollPaneBody;
    JScrollPane scrollPaneTip;
	int ctr=0;
	
	Set<Dictionary> dictionarySet = new LinkedHashSet<Dictionary>();

    public ITdictionary() {
    

    	Border empty = BorderFactory.createEmptyBorder();
    	Border loweredBevel = BorderFactory.createLoweredBevelBorder();

        searchTextField = new JTextField(20);
		searchTextField.setText("I am looking for...");
        searchTextField.setFont(new Font("Lucida Console", Font.PLAIN, 25));
        searchTextField.selectAll();
        searchTextField.addMouseListener(new CursorListener());

        outputDefTextArea = new JTextArea(15, 80);
		outputDefTextArea.setFont(new Font("Lucida Console", Font.PLAIN, 18));


		tipOftheDayTextArea = new JTextArea(3, 80);
		tipOftheDayTextArea.setFont(new Font("Lucida Console", Font.PLAIN, 11));

		ImageIcon search = new ImageIcon("icons/Search.png");
		ImageIcon logoIcon = new ImageIcon("icons/ITlogo2.png");
		ImageIcon home = new ImageIcon("icons/home3.png");
		ImageIcon about = new ImageIcon("icons/aboutus2.png");
		ImageIcon help = new ImageIcon("icons/help2.png");
		ImageIcon add = new ImageIcon("icons/addterm.png");
		ImageIcon added = new ImageIcon("icons/myterms.png");
		ImageIcon clear = new ImageIcon("icons/ccleaner.png");
		//ImageIcon zz = new ImageIcon("icons/f.png");

		logoBtn = new JButton(logoIcon);
		logoBtn.setBackground(Color.white);
        logoBtn.setForeground(Color.black);
        logoBtn.setBorder(empty);

        searchBtn = new JButton(search);
        searchBtn.setBackground(Color.white);
        searchBtn.setForeground(Color.black);
        searchBtn.setBorder(empty);
        searchBtn.addActionListener(this);

        homeBtn = new JButton(home);
        homeBtn.setBackground(Color.white);
        homeBtn.setForeground(Color.black);
        homeBtn.setBorder(empty);

        aboutBtn = new JButton(about);
        aboutBtn.setBackground(Color.white);
        aboutBtn.setForeground(Color.black);
        aboutBtn.setBorder(empty);

        helpBtn = new JButton(help);
        helpBtn.setBackground(Color.white);
        helpBtn.setForeground(Color.black);
        helpBtn.setBorder(empty);
        
        authorizeBtn = new JButton("Edit");
        authorizeBtn.setBackground(Color.white);
        authorizeBtn.setForeground(Color.black);
        authorizeBtn.setBorder(empty);
        authorizeBtn.addActionListener(this);
        
        verifyBtn = new JButton("Verify");
        verifyBtn.setBackground(Color.white);
        verifyBtn.setForeground(Color.black);
        verifyBtn.setBorder(empty);
        verifyBtn.addActionListener(this);
        
        approveBtn = new JButton("ApproveWords");
		approveBtn.setBackground(Color.white);
		approveBtn.setForeground(Color.black);
		approveBtn.setBorder(empty);
		approveBtn.addActionListener(this);
		
		allBtn = new JButton("ALL");
		allBtn.setBackground(Color.white);
		allBtn.setForeground(Color.black);
		allBtn.setBorder(empty);
		allBtn.addActionListener(this);
			
        addTermBtn = new JButton(add);
        addTermBtn.setBackground(Color.white);
        addTermBtn.setForeground(Color.black);
        addTermBtn.setBorder(empty);
        addTermBtn.addActionListener(this);

        myTermsBtn = new JButton(added);
        myTermsBtn.setBackground(Color.white);
        myTermsBtn.setForeground(Color.black);
        myTermsBtn.setBorder(empty);
        myTermsBtn.addActionListener(this);

        clearBtn = new JButton(clear);
        clearBtn.setBackground(Color.white);
        clearBtn.setForeground(Color.black);
        clearBtn.setBorder(empty);
        clearBtn.addActionListener(this);


        a = new JButton(new ImageIcon("icons/a.png"));
        a.setBackground(Color.LIGHT_GRAY);
        a.setForeground(Color.black);
        a.setBorder(empty);
        a.addActionListener(this);

        b = new JButton(new ImageIcon("icons/b.png"));
        b.setBackground(Color.LIGHT_GRAY);
        b.setForeground(Color.black);
        b.setBorder(empty);
        b.addActionListener(this);

        c = new JButton(new ImageIcon("icons/c.png"));
        c.setBackground(Color.LIGHT_GRAY);
        c.setForeground(Color.black);
        c.setBorder(empty);
        c.addActionListener(this);

        d = new JButton(new ImageIcon("icons/d.png"));
        d.setBackground(Color.LIGHT_GRAY);
        d.setForeground(Color.black);
        d.setBorder(empty);
        d.addActionListener(this);

        e = new JButton(new ImageIcon("icons/e.png"));
        e.setBackground(Color.LIGHT_GRAY);
        e.setForeground(Color.black);
        e.setBorder(empty);
        e.addActionListener(this);

        f = new JButton(new ImageIcon("icons/f.png"));
        f.setBackground(Color.LIGHT_GRAY);
        f.setForeground(Color.black);
        f.setBorder(empty);
        f.addActionListener(this);

        g = new JButton(new ImageIcon("icons/g.png"));
        g.setBackground(Color.LIGHT_GRAY);
        g.setForeground(Color.black);
        g.setBorder(empty);
        g.addActionListener(this);

        h = new JButton(new ImageIcon("icons/h.png"));
        h.setBackground(Color.LIGHT_GRAY);
        h.setForeground(Color.black);
        h.setBorder(empty);
        h.addActionListener(this);

        i = new JButton(new ImageIcon("icons/i.png"));
        i.setBackground(Color.LIGHT_GRAY);
        i.setForeground(Color.black);
        i.setBorder(empty);
        i.addActionListener(this);

        j = new JButton(new ImageIcon("icons/j.png"));
        j.setBackground(Color.LIGHT_GRAY);
        j.setForeground(Color.black);
        j.setBorder(empty);
        j.addActionListener(this);

        k = new JButton(new ImageIcon("icons/k.png"));
        k.setBackground(Color.LIGHT_GRAY);
        k.setForeground(Color.black);
        k.setBorder(empty);
        k.addActionListener(this);

        l = new JButton(new ImageIcon("icons/l.png"));
        l.setBackground(Color.LIGHT_GRAY);
        l.setForeground(Color.black);
        l.setBorder(empty);
        l.addActionListener(this);

        m = new JButton(new ImageIcon("icons/m.png"));
        m.setBackground(Color.LIGHT_GRAY);
        m.setForeground(Color.black);
        m.setBorder(empty);
        m.addActionListener(this);

        n = new JButton(new ImageIcon("icons/n.png"));
        n.setBackground(Color.LIGHT_GRAY);
        n.setForeground(Color.black);
        n.setBorder(empty);
        n.addActionListener(this);

        o = new JButton(new ImageIcon("icons/o.png"));
        o.setBackground(Color.LIGHT_GRAY);
        o.setForeground(Color.black);
        o.setBorder(empty);
        o.addActionListener(this);

        p = new JButton(new ImageIcon("icons/p.png"));
        p.setBackground(Color.LIGHT_GRAY);
        p.setForeground(Color.black);
        p.setBorder(empty);
        p.addActionListener(this);

        q = new JButton(new ImageIcon("icons/q.png"));
        q.setBackground(Color.LIGHT_GRAY);
        q.setForeground(Color.black);
        q.setBorder(empty);
        q.addActionListener(this);

        r = new JButton(new ImageIcon("icons/r.png"));
        r.setBackground(Color.LIGHT_GRAY);
        r.setForeground(Color.black);
        r.setBorder(empty);
        r.addActionListener(this);

        s = new JButton(new ImageIcon("icons/s.png"));
        s.setBackground(Color.LIGHT_GRAY);
        s.setForeground(Color.black);
        s.setBorder(empty);
        s.addActionListener(this);

        t = new JButton(new ImageIcon("icons/t.png"));
        t.setBackground(Color.LIGHT_GRAY);
        t.setForeground(Color.black);
        t.setBorder(empty);
        t.addActionListener(this);

        u = new JButton(new ImageIcon("icons/u.png"));
        u.setBackground(Color.LIGHT_GRAY);
        u.setForeground(Color.black);
        u.setBorder(empty);
        u.addActionListener(this);

        v = new JButton(new ImageIcon("icons/v.png"));
        v.setBackground(Color.LIGHT_GRAY);
        v.setForeground(Color.black);
        v.setBorder(empty);
        v.addActionListener(this);

        w = new JButton(new ImageIcon("icons/w.png"));
        w.setBackground(Color.LIGHT_GRAY);
        w.setForeground(Color.black);
        w.setBorder(empty);
        w.addActionListener(this);

        x = new JButton(new ImageIcon("icons/x.png"));
        x.setBackground(Color.LIGHT_GRAY);
        x.setForeground(Color.black);
        x.setBorder(empty);
        x.addActionListener(this);

        y = new JButton(new ImageIcon("icons/y.png"));
        y.setBackground(Color.LIGHT_GRAY);
        y.setForeground(Color.black);
        y.setBorder(empty);
        y.addActionListener(this);

        z = new JButton(new ImageIcon("icons/z.png"));
        z.setBackground(Color.LIGHT_GRAY);
        z.setForeground(Color.black);
        z.setBorder(empty);
        z.addActionListener(this);



		indexPanel = new JPanel();
		//indexPanel.setLayout(new GridLayout(26 , 1 , 0 ,0));
		indexPanel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		indexPanel.setBackground(Color.LIGHT_GRAY);
		//indexPanel.add(new JLabel("Show all terms in this letter: "));

		indexPanel.add(a);
		indexPanel.add(b);
		indexPanel.add(c);
		indexPanel.add(d);
		indexPanel.add(e);
		indexPanel.add(f);
		indexPanel.add(g);
		indexPanel.add(h);
		indexPanel.add(i);
		indexPanel.add(j);
		indexPanel.add(k);
		indexPanel.add(l);
		indexPanel.add(m);
		indexPanel.add(n);
		indexPanel.add(o);
		indexPanel.add(p);
		indexPanel.add(q);
		indexPanel.add(r);
		indexPanel.add(s);
		indexPanel.add(t);
		indexPanel.add(u);
		indexPanel.add(v);
		indexPanel.add(w);
		indexPanel.add(x);
		indexPanel.add(y);
		indexPanel.add(z);

		//buttonsPanel = new JPanel();
		//buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
        //buttonsPanel.setBackground(Color.white);
        //buttonsPanel.add(addTermBtn);
        //buttonsPanel.add(myTermsBtn);
        //buttonsPanel.add(new JLabel(" "));
		//buttonsPanel.add(indexPanel);


			menuPanel = new JPanel();
        	menuPanel.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
       		menuPanel.setBackground(Color.LIGHT_GRAY);
        	menuPanel.add(new JLabel("            "));
       		menuPanel.add(homeBtn);
        	menuPanel.add(addTermBtn);
        	menuPanel.add(myTermsBtn);
        	menuPanel.add(aboutBtn);
        	menuPanel.add(helpBtn);
        	menuPanel.add(authorizeBtn);
        	menuPanel.add(verifyBtn);
        	menuPanel.add(approveBtn);
        	menuPanel.add(allBtn);
        	menuPanel.add(new JLabel("           "));
		
			
		
		
        //menuPanel.add();
        //menuPanel.add(indexPanel);


		scrollPaneTip = new JScrollPane(tipOftheDayTextArea);
		scrollPaneBody = new JScrollPane(outputDefTextArea);



		JPanel tipPanel = new JPanel();
		tipPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,0,0));
		tipPanel.setBackground(Color.LIGHT_GRAY);
		tipPanel.add(scrollPaneTip);
		tipPanel.add(new JLabel("               "));

		JPanel headPanel = new JPanel();
		headPanel.setLayout(new BorderLayout());
		headPanel.setBackground(Color.LIGHT_GRAY);
		headPanel.add(menuPanel, BorderLayout.WEST);
		headPanel.add(tipPanel, BorderLayout.EAST);
		headPanel.add(new JLabel(" "), BorderLayout.SOUTH);
		headPanel.add(new JLabel(" "), BorderLayout.NORTH);


		logoPanel = new JPanel();
		logoPanel.setLayout(new BorderLayout());
		logoPanel.setBackground(Color.LIGHT_GRAY);
		logoPanel.add(logoBtn, BorderLayout.WEST);

		JPanel spacePanel1 = new JPanel();
		spacePanel1.setLayout(new BorderLayout());
		spacePanel1.setBackground(Color.LIGHT_GRAY);
		spacePanel1.add(new JLabel(" "), BorderLayout.SOUTH);

		JPanel spacePanel2 = new JPanel();
		spacePanel2.setLayout(new BorderLayout());
		spacePanel2.setBackground(Color.LIGHT_GRAY);
		spacePanel2.add(new JLabel(" "), BorderLayout.SOUTH);

		JPanel spacePanel3 = new JPanel();
		spacePanel3.setLayout(new BorderLayout());
		spacePanel3.setBackground(Color.LIGHT_GRAY);
		spacePanel3.add(new JLabel(" "), BorderLayout.SOUTH);

		JPanel hPanel = new JPanel();
		hPanel.setLayout(new BorderLayout());
		hPanel.setBackground(Color.LIGHT_GRAY);
		hPanel.add(searchTextField, BorderLayout.CENTER);
        hPanel.add(searchBtn, BorderLayout.EAST);



        headerPanel = new JPanel();
        headerPanel.setLayout(new BorderLayout());
      	headerPanel.setBorder(empty);
        headerPanel.setBackground(Color.LIGHT_GRAY);
        headerPanel.add(headPanel, BorderLayout.NORTH);
        headerPanel.add(hPanel, BorderLayout.CENTER);
        headerPanel.add(new JLabel("               "), BorderLayout.EAST);
        headerPanel.add(new JLabel("            "), BorderLayout.WEST);



		mainHeaderPanel = new JPanel();
		mainHeaderPanel.setLayout(new BorderLayout());
		//mainHeaderPanel.add(logoPanel, BorderLayout.EAST);
		mainHeaderPanel.add(headerPanel, BorderLayout.CENTER);

		outputPanel = new JPanel();
		outputPanel.setLayout(new BorderLayout());
        outputPanel.setBackground(Color.LIGHT_GRAY);
        outputPanel.add(scrollPaneBody, BorderLayout.CENTER);
        outputPanel.add(spacePanel1, BorderLayout.NORTH);
        outputPanel.add(new JLabel("            "), BorderLayout.WEST);
        outputPanel.add(new JLabel("                "), BorderLayout.EAST);


        JPanel footPanel = new JPanel();
        footPanel.setLayout(new BorderLayout());
        footPanel.setBackground(Color.LIGHT_GRAY);
        footPanel.add(new JLabel("            "), BorderLayout.WEST);
        footPanel.add(indexPanel, BorderLayout.CENTER);
        footPanel.add(clearBtn, BorderLayout.EAST);



        footerPanel = new JPanel();
        footerPanel.setLayout(new BorderLayout());
        footerPanel.setBackground(Color.LIGHT_GRAY);
        footerPanel.add(new JLabel("                "), BorderLayout.EAST);
        footerPanel.add(footPanel, BorderLayout.CENTER);
        footerPanel.add(spacePanel2, BorderLayout.SOUTH);
        footerPanel.add(spacePanel3, BorderLayout.NORTH);





        setLayout(new BorderLayout());
		add(mainHeaderPanel, BorderLayout.NORTH);
		add(outputPanel, BorderLayout.CENTER);
		add(footerPanel,BorderLayout.SOUTH);


		loadTextFile();
		showWordOfTheDay();

    }

    public void actionPerformed(ActionEvent ae){
		Object source = ae.getSource();

		if(source == searchBtn){
				outputDefTextArea.setText("");
				showWord();
		}
		
		if(source == a) {
				String id2 = "A";
				searchWords(id2);
		}
		if(source == b) {
				String id2 = "B";
				searchWords(id2);
		}
		if(source == c) {
				String id2 = "C";
				searchWords(id2);
		}
		if(source == d) {
				String id2 = "D";
				searchWords(id2);
		}
		if(source == e) {
				String id2 = "E";
				searchWords(id2);
		}
		if(source == f) {
				String id2 = "F";
				searchWords(id2);
		}
		if(source == g) {
				String id2 = "G";
				searchWords(id2);
		}
		if(source == h) {
				String id2 = "H";
				searchWords(id2);
		}
		if(source == i) {
				String id2 = "I";
				searchWords(id2);
		}
		if(source == j) {
				String id2 = "J";
				searchWords(id2);
		}
		if(source == k) {
				String id2 = "K";
				searchWords(id2);
		}
		if(source == l) {
				String id2 = "L";
				searchWords(id2);
		}
		if(source == m) {
				String id2 = "M";
				searchWords(id2);
		}
		if(source == n) {
				String id2 = "N";
				searchWords(id2);
		}
		if(source == o) {
				String id2 = "O";
				searchWords(id2);
		}
		if(source == p) {
				String id2 = "P";
				searchWords(id2);
		}
		if(source == q) {
				String id2 = "Q";
				searchWords(id2);
		}
		if(source == r) {
				String id2 = "R";
				searchWords(id2);
		}
		if(source == s) {
				String id2 = "S";
				searchWords(id2);
		}
		if(source == t) {
				String id2 = "T";
				searchWords(id2);
		}
		if(source == u) {
				String id2 = "U";
				searchWords(id2);
		}
		if(source == v) {
				String id2 = "V";
				searchWords(id2);
		}
		if(source == w) {
				String id2 = "W";
				searchWords(id2);
		}
		if(source == x) {
				String id2 = "X";
				searchWords(id2);
		}
		if(source == y) {
				String id2 = "Y";
				searchWords(id2);
		}
		if(source == z) {
				String id2 = "Z";
				searchWords(id2);
		}
		if(source == clearBtn){
			outputDefTextArea.setText("");
			searchTextField.setText("");
		}
		if(source == addTermBtn){
			addTerms();
		}
		if(source == myTermsBtn){
			outputDefTextArea.setText("");
			addedTerms();
		}
		if(source == authorizeBtn){
			login();
			editWords();
		}
		if(source == verifyBtn){
			login();
			verify();
		}
		if(source == approveBtn){
			login();
			approve();
		}
		if(source == allBtn){
			viewAll();
		}


	}

	public void loadTextFile() {
		try {
			Scanner input = new Scanner(new File("ITterms.txt"));

			while (input.hasNextLine()) {
				String text = input.nextLine();

				dictionarySet.add(Dictionary.parseData(text));
			}

		} catch(Exception e) {

		}
	}
	
	public void addedTerms(){
		setLayout(new BorderLayout());
		add(mainHeaderPanel, BorderLayout.NORTH);
		add(outputPanel, BorderLayout.CENTER);
		//add(footerPanel,BorderLayout.SOUTH);
		
	}
	
	public void loadTextFile2(){
		Set<Dictionary> dictionarySetAddedTerms = new LinkedHashSet<Dictionary>();
		try {
			Scanner input = new Scanner(new File("Final.txt"));
			
			
			while (input.hasNextLine()) {
				String text = input.nextLine();

				dictionarySetAddedTerms.add(Dictionary.parseData(text));
			}
			
			for (Dictionary elem: dictionarySetAddedTerms) {
				outputDefTextArea.append(elem.itWord + "- " + elem.meaning + "\n");
				outputDefTextArea.setLineWrap( true );
				outputDefTextArea.setWrapStyleWord( true );
				outputDefTextArea.setEditable(false);
			}

		} catch(Exception e) {

		}
	}
	
	public void viewAll(){
		for (Dictionary element: dictionarySet) {
			outputDefTextArea.append(element.itWord + "- " + element.meaning + "\n\n");
			outputDefTextArea.setLineWrap( true );
			outputDefTextArea.setWrapStyleWord( true );
			outputDefTextArea.setEditable(false);
				
			
		}
	}
	
	public void showWordOfTheDay(){
		String[] s = new String[dictionarySet.size()];
		int r = 0;
		int num = dictionarySet.size();
		Random randomGenerator = new Random();
		int randomInt = randomGenerator.nextInt(num);
		
		for (Dictionary element: dictionarySet) {
			s[r] = (element.itWord + "- " + element.meaning);
			r++;
		}
		tipOftheDayTextArea.append(s[randomInt]);
		tipOftheDayTextArea.setLineWrap( true );
		tipOftheDayTextArea.setWrapStyleWord( true );
		tipOftheDayTextArea.setEditable(false);

	}

	public void showWord() {
		String id = searchTextField.getText();
		// for each element in dictionarySet
		for (Dictionary element: dictionarySet) {

			if (element.itWord.equalsIgnoreCase(id)){
				outputDefTextArea.setText(element.itWord + "- " + element.meaning + "\n");
				outputDefTextArea.setLineWrap( true );
				outputDefTextArea.setWrapStyleWord( true );
				outputDefTextArea.setEditable(false);
			}



		} // end of for
		
		if(outputDefTextArea.getText().equalsIgnoreCase("")){
			JOptionPane.showMessageDialog(null, "No matches found!");
		} 



	}
	
	public void searchWords(String id){
		
		outputDefTextArea.setText("");
		
		for (Dictionary element: dictionarySet) {
			
			if (element.itWord.startsWith(id)) {
				outputDefTextArea.append(element.itWord + "- " + element.meaning + "\n\n");
				outputDefTextArea.setLineWrap( true );
				outputDefTextArea.setWrapStyleWord( true );
				outputDefTextArea.setEditable(false);
				
			}
		}
	}
	
	public void addTerms(){
			try {
			
			
		int x=0;
		String website = "";
		String term = "";
		String definition = "";
		
  		while(x == 0){
  		JTextArea 	yourSiteArea; 
  		JTextArea 	termArea;
  		JTextArea	definitionArea;
  		JButton browserBtn;
  		
  		yourSiteArea = new JTextArea(website);
  		yourSiteArea.setColumns(40);
  		yourSiteArea.setLineWrap( true );
  		yourSiteArea.setWrapStyleWord( true );
  		
  		termArea = new JTextArea(term);
  		termArea.setColumns(50);
  		termArea.setLineWrap( true );
  		termArea.setWrapStyleWord( true );
  		
  		definitionArea = new JTextArea(definition);	
  		definitionArea.setColumns(40);
  		definitionArea.setRows(15);
  		definitionArea.setLineWrap( true );
  		definitionArea.setWrapStyleWord( true );
  		
  		browserBtn = new JButton("Open Browser");
  		browserBtn.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent ae) {
					openBrowser();
				}
			}
		);
  		
  		 	 	 
		JPanel yourSitePanel = new JPanel();
		yourSitePanel.setLayout(new FlowLayout(FlowLayout.LEFT,1,1));
		yourSitePanel.setBorder(new TitledBorder("Your site"));
		yourSitePanel.setBackground(Color.white);
		yourSitePanel.add(yourSiteArea);
		yourSitePanel.add(browserBtn);
		
		JPanel termPanel = new JPanel();
		termPanel.setLayout(new FlowLayout(FlowLayout.LEFT,1,1));
		termPanel.setBackground(Color.white);
		termPanel.setBorder(new TitledBorder("Term"));
		termPanel.add(termArea);
		
		JPanel defPanel = new JPanel();
		defPanel.setLayout(new FlowLayout(FlowLayout.LEFT,1,1));
		defPanel.setBackground(Color.white);
		defPanel.setBorder(new TitledBorder("Definition"));
		defPanel.add(definitionArea);
		
		JPanel addPanel = new JPanel();
  	 	addPanel.setLayout(new BorderLayout());
  	 	addPanel.add(yourSitePanel, BorderLayout.NORTH);
  	 	addPanel.add(termPanel, BorderLayout.CENTER);
  	 	addPanel.add(defPanel, BorderLayout.SOUTH);
  	 	
 		
  	 	JOptionPane.showMessageDialog(null, addPanel, "Add Term",JOptionPane.PLAIN_MESSAGE);
  		website = yourSiteArea.getText();
  		term = termArea.getText();
  		definition = definitionArea.getText();	
  			
  			if(website.equalsIgnoreCase("") || term.equalsIgnoreCase("") || definition.equalsIgnoreCase("")){
  		 			x=0;
  		 			JOptionPane.showMessageDialog(null, "Please fill up all the text fields...");
  			}else {
  		 			x=1;
  		 			BufferedWriter output2 = new BufferedWriter(new FileWriter("Added Terms.txt", true));
    				output2.append(termArea.getText() + "::" + definitionArea.getText() + " Source: " + yourSiteArea.getText());
    				output2.newLine();
					output2.close();    				
    				
  			}
  		
  		}
  		 		
  		}  catch (IOException ex) {
			
		}
  		 	 	 
	 }
	 
	 public void editWords(){ //edit
	 	int counter = 0;
		try{
			Runtime.getRuntime().exec("notepad Added Terms.txt");
			openBrowser();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
		
	 		
	 }
	 
	 public void verify(){ //verify
	 	Set<Dictionary> dictionarySetInitFinal = new LinkedHashSet<Dictionary>();
	 	
	 	try{
	 		Scanner input2 = new Scanner(new File("Added Terms.txt"));
				
			while (input2.hasNextLine()) {
				String text = input2.nextLine();

				dictionarySetInitFinal.add(Dictionary.parseData(text));
			}
			
			BufferedWriter outputInit = new BufferedWriter(new FileWriter("Final.txt", true));
			
			for (Dictionary elem: dictionarySetInitFinal) {
				outputInit.append(elem.itWord + "::" + elem.meaning);
				outputInit.newLine();
    							
			}
			outputInit.close();
			
	 		
	 	} catch (IOException ex) {
			ex.printStackTrace();
		}
	 }
	 
	 public void approve(){ //final
	 	Set<Dictionary> dictionarySetFinalAddedTerms = new LinkedHashSet<Dictionary>();
	 	
	 	try{
			Scanner input = new Scanner(new File("Final.txt"));
				
			while (input.hasNextLine()) {
				String text = input.nextLine();

				dictionarySetFinalAddedTerms.add(Dictionary.parseData(text));
			}
			
						
			dictionarySet.clear();
			
			BufferedWriter output = new BufferedWriter(new FileWriter("ITterms.txt", true));
			
			for (Dictionary elem: dictionarySetFinalAddedTerms) {
				output.newLine();
				output.append(elem.itWord + "::" + elem.meaning);
    							
			}
			
			output.close();
			loadTextFile();
			
			repaint();
			
	 	} catch (IOException ex) {
			ex.printStackTrace();
		}
	 }
	 
	 public void openBrowser(){
	 	String url = "http://www.google.com";

        if(Desktop.isDesktopSupported()){
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URI(url));
            } catch (IOException | URISyntaxException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            Runtime runtime = Runtime.getRuntime();
            try {
                runtime.exec("xdg-open " + url);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
	 }
	 
	 

	
		
    	public static void main(String[] args) throws IOException {
		JFrame frame = new ITdictionary();

		frame.setTitle("Clamt IT Dictionary");
		frame.setExtendedState(MAXIMIZED_BOTH);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);

	}
		public void login(){
			String text = "";
			String text2 = "";
			
			while(ctr == 0){
 		 	JTextArea textArea = new JTextArea(text);
 		 	JTextArea textArea2 = new JTextArea(text2);
  		 	textArea.setColumns(30);
  	 		textArea.setLineWrap( true );
  	 		textArea.setWrapStyleWord( true );
  	 		textArea.setSize(textArea.getPreferredSize().width, 1);
  	 		textArea2.setColumns(30);
  	 		textArea2.setLineWrap( true );
  	 		textArea2.setWrapStyleWord( true );
  	 		textArea2.setSize(textArea.getPreferredSize().width, 1);
  	 		
  	 		JPanel loginPanel = new JPanel();
  	 		loginPanel.setLayout(new FlowLayout(FlowLayout.LEFT,2,1));
  	 		loginPanel.add(new JLabel("Login ID:     "));
  	 		loginPanel.add(textArea);
  	 		
  	 		JPanel passwdPanel = new JPanel();
  	 		passwdPanel.setLayout(new FlowLayout(FlowLayout.LEFT,2,1));
  	 		passwdPanel.add(new JLabel("Password: "));
  	 		passwdPanel.add(textArea2);
  	 		
  	 		JPanel addPanel = new JPanel();
  	 		addPanel.setLayout(new BorderLayout());
  	 		addPanel.add(loginPanel, BorderLayout.NORTH);
  	 		addPanel.add(passwdPanel, BorderLayout.CENTER);
  	 		
  	 		JOptionPane.showMessageDialog(null, addPanel, "Login",JOptionPane.PLAIN_MESSAGE);
  	 		text = textArea.getText();
  	 		text2 = textArea2.getText();
  	 		
  	 			while ((!(text.equalsIgnoreCase("guest"))) && (!(text.equalsIgnoreCase("admin"))) && (!(text.equalsIgnoreCase("admin"))) && 
  	 				    (!(text.equalsIgnoreCase("admin")))){
  	 				JOptionPane.showMessageDialog(null, "Error! Please check your login id and password..");
  	 				JOptionPane.showMessageDialog(null, addPanel, "Login",JOptionPane.PLAIN_MESSAGE);
  	 				text = textArea.getText();
  	 				text2 = textArea2.getText();
  	 			}
  	 			ctr=1;
  	 		
  	 		}
  	 				
		}
         class CursorListener implements MouseListener{

		public void mouseReleased(MouseEvent me){
			//not used
		}
		public void mousePressed(MouseEvent me){
			//not used
		}
		public void mouseEntered(MouseEvent me){
			//not used
		}
		public void mouseExited(MouseEvent me){
			//not used
		}
		public void mouseClicked(MouseEvent me){
			searchTextField.selectAll();
		}
	}


}
